﻿using System;
using System.Collections.Generic;
using System.Text;
using AspNetCs.DALFactory;
using AspNetCs.IDAL;
using AspNetCs.Model;
using System.Data;

namespace AspNetCs.Bll
{
    public class UserPhoto
    {
        IUserPhoto UserPhoto_Factory = Conn.CreateUserPhoto();
        IUserPhoto_Class UserPhotoClass_Factory = Conn.CreatePhotoClass();
        /// <summary>
        /// 添加用户图片
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public int Add(UserPhoto_Model md)
        {
            if (md == null) return -1;
            return UserPhoto_Factory.Add(md);
        }
        public int delete(int id)
        {
            if (id <= 0) return 0;
            return UserPhoto_Factory.delete(" id=" + id.ToString());
        }

        public UserPhoto_Model GetModel(int id)
        {
            UserPhoto_Model md = new UserPhoto_Model();
            DataTable dt = GetDataTable("  id=" + id.ToString());
            if (dt.Rows.Count > 0)
            {
                md = UserPhoto_Factory.GetModel(dt.Rows[0]);
            }
            return md;
        }
        public DataTable GetDataTable(string filter)
        {
            DataTable dt = new DataTable();
            if (filter != "")
            {
                dt = UserPhoto_Factory.GetDataTable(filter);
            }


            return dt;
        }

        /// <summary>
        /// 分类DATATABLE
        /// </summary>
        /// <param name="filter">条件,不要跟"where"</param>
        /// <returns></returns>
        public DataTable GetDataTable_Class(string filter)
        {
            return UserPhotoClass_Factory.GetDataTable(filter);
        }

        /// <summary>
        /// 更新分类
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public int UpdateClass(UserPhoto_Class_Model md)
        {
            if (md == null) return -1;
            return UserPhotoClass_Factory.Update(md);
        }

        public int AddClass(UserPhoto_Class_Model md)
        {
            if (md == null) return -1;
            return UserPhotoClass_Factory.Add(md);
        }
        public int delClass(int _id)
        {
            if (_id <= 0) return -1;
            UserPhoto_Class_Model md = new UserPhoto_Class_Model();
            md.Id = _id;
            return UserPhotoClass_Factory.del(md);
        }
        public T UserPhoto_Class_Column<T>(string columnName, int id)
        {
            return UserPhotoClass_Factory.GetModelColumn<T>(columnName, id);
        }
        public UserPhoto_Class_Model GetModelClass(int id)
        {
            UserPhoto_Class_Model md = new UserPhoto_Class_Model();
            DataTable dt = UserPhotoClass_Factory.GetDataTable(" id=" + id.ToString());
            foreach (DataRow dr in dt.Rows)
            {
                md = UserPhotoClass_Factory.GetModel(dr);
            }
            return md;
        }
        /// <summary>
        /// 更新审核
        /// </summary>
        /// <param name="md"></param>
        /// <returns></returns>
        public int UpdateCheck(UserPhoto_Model md)
        {
            if (md == null) return -1;
            return UserPhoto_Factory.UpdateCheck(md);
        }
        public int Update(UserPhoto_Model md)
        {
            if (md == null) return -1;
            return UserPhoto_Factory.Update(md); 
        }



    }
}
